﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Business.Classes;
using DAL;

namespace UI
{
    public partial class manterPatrocinio : System.Web.UI.Page
    {
        PropagandaBusiness propagandaBusiness = new PropagandaBusiness();
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                Usuario user = (Usuario)Session["user"];
                if (user == null)
                {
                    Response.Redirect(new Controlador.Controladora().GetPageLogin());
                }
                if (!IsPostBack)
                {
                    fillGridView();
                }
            }
            catch (Exception)
            {
                
                throw;
            }
        }

        protected void gvPatrocinio_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            gvPatrocinio.EditIndex = e.RowIndex;
            fillGridView();

            Propaganda propaganda = propagandaBusiness.getPropagandaByID(Convert.ToInt32(gvPatrocinio.DataKeys[e.RowIndex]["idPropaganda"]));

            propagandaBusiness.deletePropaganda(propaganda);
            fillGridView();


        }

        protected void gvPatrocinio_RowEditing(object sender, GridViewEditEventArgs e)
        {

        }

        protected void InsertPropaganda(object sender, EventArgs e)
        {
            Response.Redirect("~/incluirPatrocinio.aspx");
        }

        private void fillGridView()
        {
            try
            {
                gvPatrocinio.DataSource = propagandaBusiness.getAllPropaganda();
                gvPatrocinio.DataBind();
            }
            catch (Exception)
            {
                
                throw;
            }
        }

        protected void InsertPropaganga(object sender, EventArgs e)
        {

        }

        protected void gvPatrocinio_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void btNew_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/incluirPatrocinio.aspx");
        }

       
    }
}
